package com.lq.controller;

import com.lq.pojo.Category;
import com.lq.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.List;

@Controller
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/getCategory")
    public String getCategory(Model model) {

        List<Category> categoryList = categoryService.getAllCategory();

        model.addAttribute("categoryList", categoryList);

        return "publish";
    }


    @RequestMapping("/insertCategory")
    public String insertCategory(String categoryName, Model model) throws ServletException, IOException {

        if (categoryService.insertCategory(categoryName)) {

            model.addAttribute("isInsertCategorySuccess", true);
        }

        return "forward:/getTag";
    }
}
